use specs::{Read, ReadStorage, WriteStorage, System};

use crate::res::position_storage::Position;
use crate::res::velocity_storage::Velocity;
use crate::res::delta_time::DeltaTime;

pub struct MovementSystem;

impl<'a> System<'a> for MovementSystem {
    type SystemData = (
        Read<'a, DeltaTime>,
        WriteStorage<'a, Position>,
        ReadStorage<'a, Velocity>,
    );

    fn run(&mut self, data: Self::SystemData) {
        use specs::Join;

        let (delta, mut position, velocity) = data;

        for (position, velocity) in (&mut position, &velocity).join() {
            position.x += velocity.x * delta.0;
            position.y += velocity.y * delta.0;
        }
    }
}